#include "stdafx.h"
#include "Button2D.h"
#include "ResourceManager.h"

Button2D::Button2D()
{
	m_NumModel = 1;
	m_Models = new Model*[1];
	m_Models[0] = new Model[1];
	Vertex* vertexData = new Vertex[4];
	vertexData[0].position = Vector3(0.0f, 0.0f, 0.0f);
	vertexData[0].texcoord = Vector2(0.0f, 0.0f);
	vertexData[1].position = Vector3(0.0f, 1.0f, 0.0f);
	vertexData[1].texcoord = Vector2(0.0f, 1.0f);
	vertexData[2].position = Vector3(1.0f, 1.0f, 0.0f);
	vertexData[2].texcoord = Vector2(1.0f, 1.0f);
	vertexData[3].position = Vector3(1.0f, 0.0f, 0.0f);
	vertexData[3].texcoord = Vector2(1.0f, 0.0f);
	m_Models[0]->SetVertices(vertexData, 4);
	GLushort indices[6] = { 0, 1, 2,0,2,3 };
	m_Models[0]->SetIndices(indices, 6);
	this->setShader(ResourceManager::GetInstance()->textureShader);
	this->SetPostion(Vector3(10.0f, 0.0f, 0.0f));
	/*this->SetModel(ResourceManager::GetInstance()->hcn);
	this->SetScaleFactor(Vector3(0.5f, 0.5f, 0.5f));
	this->v3Position = Vector3(0.0f, 0.0f, 1.0f);
	this->SetShader(ResourceManager::GetInstance()->triangleShader);*/
}


Button2D::~Button2D()
{
	
}

void Button2D::draw()
{

	glUseProgram(m_Shader->program);
	for (int i = 0; i < m_NumModel; i++)
	{
		m_Models[i]->draw(m_Shader);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Models[i]->IND);
		glDrawElements(GL_TRIANGLES, m_Models[i]->getNumIndices(), GL_UNSIGNED_SHORT, 0);

	/*	const unsigned int MaterialIndex = m_Models[i]->getTextureID();
		int index = MaterialIndex * 2;
		if (MaterialIndex < m_NumTextures && m_Textures[MaterialIndex])
		{
			m_Textures[index]->Bind(GL_TEXTURE0);
			m_Textures[index + 1]->Bind(GL_TEXTURE1);
		}

		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Models[i]->IND);
		glDrawElements(GL_TRIANGLES, m_Models[i]->getNumIndices(), GL_UNSIGNED_SHORT, 0);

		m_Textures[index]->UnBind(GL_TEXTURE0);
		m_Textures[index + 1]->UnBind(GL_TEXTURE1);*/
	}

	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

}

void Button2D::update(float deltatime)
{
	//RotateUp(0.1f);
}

void Button2D::SetBackGround(char* path2Image)
{
	/*Texture *background = new Texture;
	char* path2BackGround[1];
	path2BackGround[0] = path2Image;
	background->InitTexture2D(path2BackGround, 1);
	this->SetTexture(background);
	delete background;*/
}
